import 'package:animal/constant/font.dart';
import 'package:animal/ui/friend/controller/new_friend_Controller.dart';
import 'package:animal/utils/screen_util.dart';
import 'package:animal/widgets/HeaderWidget.dart';
import 'package:animal/widgets/appbar_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swipe_action_cell/flutter_swipe_action_cell.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';

///新朋友
class NewFriendPage extends StatelessWidget {
  NewFriendPage({Key? key}) : super(key: key);

  late NewFriendController controller;

  @override
  Widget build(BuildContext context) {
    controller = Get.put(NewFriendController());
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBarWidget.defaultAppBar(title: const Text("新的朋友"), backgroundColor: Colors.white, elevation: 1, actions: [
        GFButton(
          onPressed: () {},
          text: "添加",
          textStyle: KFontConstant.myTextStyle(size: 15),
          type: GFButtonType.transparent,
        )
      ]),
      body: Column(
        children: [
          Obx(() {
            return ListView.builder(
                itemCount: controller.data.length,
                shrinkWrap: true,
                itemBuilder: (context, index) {
                  return SwipeActionCell(
                    ///这个key是必要的
                    key: ValueKey(controller.data[index]),
                    trailingActions: <SwipeAction>[
                      SwipeAction(
                          title: "delete",
                          onTap: (CompletionHandler handler) async {
                            controller.data.removeAt(index);
                          },
                          color: Colors.red),
                    ],
                    child: InkWell(
                      child: SizedBox(
                        width: double.infinity,
                        height: ScreenUtil().L(100),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Row(
                              children: [
                                Header.defaultHead(),
                                Text("${controller.data[index].nickName}", style: KFontConstant.myTextStyle(size: 14)),
                              ],
                            ),
                            CupertinoButton(
                              child: Text("同意", style: KFontConstant.myTextStyle(size: 14, color: Colors.white)),
                              onPressed: () => controller.getAgreeApply(controller.data[index].id.toString()),
                              color: Colors.blue,
                              padding: EdgeInsets.symmetric(horizontal: ScreenUtil().L(20)),
                            )
                          ],
                        ),
                      ),
                      onTap: () => controller.gotoApplyInfo(),
                    ),
                  );
                });
          })
        ],
      ),
    );
  }
}
